package com.example.photograph.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class mainMain {

    public static void main(String[] args) throws IOException {


        List<String> strings = Files.readAllLines(Paths.get("D:\\code\\github\\javamtia\\Photograph\\target\\nohup.out"));

        for (int i = 0; i < strings.size(); i++) {

            if (strings.get(i).contains("Preparing: insert into sys_user")){
                String sql = strings.get(i).replace("==>  Preparing: ","");

                String  params = strings.get(i+1).replace("==> Parameters: ", "");

                String[] split = params.split("\\), ");

                if (split.length!=6){
                    throw new RuntimeException("1231321");
                }

                String  paramsSql ="";


                for (String s : split) {
                    if (s.contains("(String)")){
                        String replace = s.replace("(String)", "");
                        paramsSql = paramsSql + "'"+replace+ "'," ;
                        continue;
                    }
                    if (s.contains("(Long)")){
                        String replace = s.replace("(Long)", "");
                        paramsSql = paramsSql + replace+ "," ;
                        continue;
                    }
                    if (s.contains("(String")){
                        String replace = s.replace("(String", "");
                        paramsSql = paramsSql + "'"+replace+ "'," ;
                    }
                    if (s.contains("(Long")){
                        String replace = s.replace("(Long", "");
                        paramsSql = paramsSql + replace+ "," ;
                    }

                }
                String substring = paramsSql.substring(0, paramsSql.length()-1);

                String replace = sql.replace(" ?, ?, ?, ?, ?, ?, ", paramsSql);
                System.out.println(replace+";");

            }


        }



    }
}
